package com.wondersgroup.framework.sample.component.demoform.action;

import java.util.ArrayList;
import java.util.List;

import com.wondersgroup.framework.core.web.struts2.action.BaseAjaxAction;
import com.wondersgroup.framework.sample.component.chart.util.ColorHelper;
import com.wondersgroup.framework.sample.component.demoform.vs.DemoVS;
import com.wondersgroup.framework.util.ChartUtils;
import com.wondersgroup.framework.util.chartmodel.MultiChartModel;
import com.wondersgroup.framework.util.chartmodel.MultiDataModel;
import com.wondersgroup.framework.util.chartmodel.SingleChartModel;

/**
 * 图表.
 * 
 * @author think
 * @version $Revision$ May 26, 2015
 * @author ($Date$ modification by $Author$)
 * @since 1.0
 */
public class ChartAction extends BaseAjaxAction {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private DemoVS demoVS;

    public DemoVS getDemoVS() {
        return demoVS;
    }

    public void setDemoVS(DemoVS demoVS) {
        this.demoVS = demoVS;
    }

    /**
     * 单系列图表.
     * 
     * @throws Exception
     */
    public void loadSingledata() throws Exception {
    	getServletResponse().setContentType("text/html;charset=utf-8");
        List<SingleChartModel> list = new ArrayList<SingleChartModel>();
        for (int i = 1; i <= 5; ++i) {
            SingleChartModel model = new SingleChartModel();
            model.setName("column" + i); // 名称
            String s = (Math.random() * 1000.0D) + "";
            s.substring(0, s.indexOf("."));
            model.setValue(s); // 值
            model.setColor(ColorHelper.getColor()); // 颜色
            model.setCode(i+"");
            list.add(model);
        }
        ChartUtils.writeXMLDataSingle(list,false,"to_showSingle");
    }

    /**
     * 多系列图表.
     * 
     * @throws Exception
     */
    public void loadMultidata() throws Exception {
    	getServletResponse().setContentType("text/html;charset=utf-8");
        List<String> nameList = new ArrayList<String>();
        List<String> codeList = new ArrayList<String>();
        for (int i = 1; i <= 4; ++i) {
            nameList.add("multicolumn" + i); // 名称列表
            codeList.add(i+"");
        }
        List<MultiDataModel> mulitList = new ArrayList<MultiDataModel>();
        for (int j = 1; j <= 3; ++j) {
            MultiDataModel multiModel = new MultiDataModel();
            multiModel.setName("multi" + j); // 名称
            multiModel.setColor(ColorHelper.getColor()); // 颜色
            multiModel.setCode(j+"");
            List<String> valueList = new ArrayList<String>();
            for (int k = 1; k <= 4; ++k) {
                String s = (Math.random() * 1000.0D) + "";
                s.substring(0, s.indexOf("."));
                valueList.add(s);
            }
            multiModel.setValues(valueList); // 值列表
            mulitList.add(multiModel);
        }
        MultiChartModel multichartmodel = new MultiChartModel();
        multichartmodel.setZName(nameList);
        multichartmodel.setZCode(codeList);
        multichartmodel.setMultiData(mulitList);
        ChartUtils.writeXMLDataMulti(multichartmodel,true,"to_showMulti");
    }

    /**
     * 多系列组合图表.
     * 
     * @throws Exception
     */
    public void loadcolumnline() throws Exception {
    	getServletResponse().setContentType("text/html;charset=utf-8");
        List<String> nameList = new ArrayList<String>();
        List<String> codeList = new ArrayList<String>();
        for (int i = 1; i <= 4; ++i){
            nameList.add("multicolumn" + i); // 名称列表
            codeList.add(i+"");
        }
        
        List<MultiDataModel> mulitList = new ArrayList<MultiDataModel>();
        for (int j = 1; j <= 3; ++j) {
            MultiDataModel multiModel = new MultiDataModel();
            multiModel.setName("multi" + j); // 名称
            if (j == 1){
            	multiModel.setParentYAxis("S"); // 折线
            }

            multiModel.setColor(ColorHelper.getColor()); // 颜色
            multiModel.setCode(j+"");
            List<String> valueList = new ArrayList<String>();
            for (int k = 1; k <= 4; ++k) {
                String s = (Math.random() * 1000.0D) + "";
                s.substring(0, s.indexOf("."));
                valueList.add(s);
            }
            multiModel.setValues(valueList);
            mulitList.add(multiModel);
        }
        MultiChartModel multichartmodel = new MultiChartModel();
        multichartmodel.setZName(nameList);
        multichartmodel.setZCode(codeList);
        multichartmodel.setMultiData(mulitList);
        ChartUtils.writeXMLDataMulti(multichartmodel,true,"to_showMulti");
    }
}
